//
//  PostBidsViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/18.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "PostBidsViewController.h"
#import "YMDDateAlertView.h"

@interface PostBidsViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *placeHolder;
@property (weak, nonatomic) IBOutlet UIButton *commitButton;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UITextField *projectName;
@property (weak, nonatomic) IBOutlet UITextField *projectMoney;

@end

@implementation PostBidsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), NO);
    
    _commitButton.layer.cornerRadius = 4*VerticalRatio();
    
    _textView.delegate = self;
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark == 提交
- (IBAction)commitHandel:(id)sender {
    
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    NSString * lan = [InternationalControl userLanguage];

    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    
    [dic setObject:_projectName.text forKey:@"mmdeName"];
    [dic setObject:_projectMoney.text forKey:@"mmdeApplyPrice"];
    [dic setObject:_timeLabel.text forKey:@"mmdeDueTime"];
    [dic setObject:_textView.text forKey:@"mmdeContent"];

    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_addMallMarketDemand withHttpType:@"POST" withTag:GS_GS_addMallMarketDemand];

}
#pragma mark == 选择时间
- (IBAction)choseTime:(id)sender {
    [self hideKeyBoard];
    YMDDateAlertView * dateView = [[YMDDateAlertView alloc]initWithTitle:@"截止日期" sureButtonTitle:@"确定" limitDate:YES dateType:0 complect:^(NSString *str) {
        _timeLabel.text = str;
    }];
    [dateView show];
}


#pragma mark - <UITextViewDelegate>


- (void)textViewDidChange:(UITextView *)textView{
    
    if (self.textView.text.length > 0) {
        self.placeHolder.hidden = YES;
    }else{
        self.placeHolder.hidden = NO;
    }
    
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag ==GS_GS_addMallMarketDemand){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
